product_list = [
    ('Iphone', 5800),
    ('MacBook Pro', 12000),
    ('Bike', 800),
    ('Watch', 10600),
    ('Coke', 3),
]
shopping_list = []
while True:
    salary=input("输入你的工资:")
    if salary.isdigit():
      salary=int(salary)
      while True:
        for index,item in enumerate(product_list):
            print(index,item)
        user_choice=input("选择商品>>:")
        if user_choice.isdigit():
            user_choice=int(user_choice)
            if user_choice<len(product_list) and user_choice>=0:
               p_item=product_list[user_choice]
               if p_item[1]<=salary:
                   shopping_list.append(p_item)
                   salary-=p_item[1]
                   print("\033[31;1m%s\033[0m added to shopping cart,your current balance is \033[31;1m%s\033[0m"%(p_item,salary))
               else: # 当商品价格大于余额
                   print("\033[41;1m你的余额不足，请选择其他商品\033[0m")
            else:
                print("商品不存在")
        elif user_choice=='q':
            print("-----shopping list-----")
            for p in shopping_list:
                print(p)
            print("your current balance is %s"%salary)
            exit() # exit() 函数，它实际上会终止整个程序的执行，而不仅仅是当前的 while 循环，这包括所有活动的循环和后续代码的执行
    else:
        print("请输入数字")